<template>
	<div class="login_page fillcontain">
		<transition name="form-fade" mode="in-out">
			<section class="form_contianer">
				<div class="manage_tip">
					<el-col :span="10" style="text-align: center;">
						<img src="../static/login.png" class="login">
					</el-col>
					<el-col :span="10">
						<p class="title">遛娃</p>
						<p class="content">运营管理后台</p>
					</el-col>
				</div>
				<el-form :model="loginForm" ref="loginForm">
					<el-form-item prop="username">
						<el-input v-model="loginForm.username" placeholder="用户名"><span>dsfsf</span></el-input>
					</el-form-item>
					<el-form-item prop="password">
						<el-input type="password" placeholder="密码" v-model="loginForm.password"></el-input>
					</el-form-item>
					<el-form-item>
						<el-button type="primary" @click="submitForm('loginForm')" class="submit_btn">登录</el-button>
					</el-form-item>
				</el-form>
			</section>
		</transition>
	</div>
</template>

<script>
	import { login } from '@/api/getData'
	import { setStore } from '@/config/mUtils'
	export default {
		data() {
			return {
				loginForm: {
					username: "",
					password: "",
				}
			}
		},
		//组件挂载完成时执行
		mounted() {
			//控制头部组件显示的状态
			this.$store.commit('changeHeaderShow', false);
		},

		methods: {
			async submitForm(formName) {
				this.$refs[formName].validate(async(valid) => {
					if(valid) {
						const res = await login({
							userName: this.loginForm.username,
							password: this.loginForm.password
						})
						if(res.code == "0") {
							this.$notify({
								title: '成功',
								message: '登录成功',
								type: 'success',
								offset: 100
							});
							//控制头部组件显示的状态
							this.$store.commit('changeHeaderShow', true);
							//控制头部组件显示的状态
							this.$store.commit('saveUser', res.user);
							//控制头部组件显示的状态
							this.$store.commit('saveMenu', res.menu);
							this.$router.push('main');
						} else {
							this.$notify.error({
								title: '错误',
								message: res.msg,
								offset: 100
							});
						}
					} else {
						this.$notify.error({
							title: '错误',
							message: '请输入正确的用户名密码',
							offset: 100
						});
						return false;
					}
				});

			}

		},

	}
</script>

<style lang="less" scoped>
	@import '../style/mixin';
	.login_page {
		background-color: #324057;
	}
	
	.login {
		width: 100px;
		height: 100px;
	}
	
	.title {
		font-size: 34px;
		margin-top: 10px;
	}
	
	.content {
		font-size: 24px;
		margin-top: 10px;
	}
	
	.manage_tip {
		position: absolute;
		width: 100%;
		top: -120px;
		left: 0;
	}
	
	.form_contianer {
		.wh(320px, 160px);
		.ctp(320px, -450px);
		padding: 25px;
		border-radius: 5px;
		background-color: #fff;
		.submit_btn {
			width: 100%;
			font-size: 16px;
		}
	}
	
	.tip {
		font-size: 12px;
		color: red;
	}
	
	.form-fade-enter-active,
	.form-fade-leave-active {
		transition: all 1s;
	}
	
	.form-fade-enter,
	.form-fade-leave-active {
		transform: translate3d(0, -50px, 0);
		opacity: 0;
	}
</style>